package website.lhc.chapter1;

/**
 * @author: longhc@citycloud.com.cn
 * @since: 2022/12/8 11:22
 * @version: 1.0
 */
public class CashContext {

    CashSuper cashSuper = null;

    /**
     * 获取对象
     *
     * @param type String
     */
    public CashContext(String type) {
        switch (type) {
            case "1":
                cashSuper = new CashNormal();
                break;
            case "2":
                cashSuper = new CashRebate(0.8);
                break;
            case "3":
                cashSuper = new CashReturn(0.9, 100);
                break;
            default:
                break;
        }
    }

    /**
     * 调用具体方法
     *
     * @param money money
     * @return double
     */
    public double getResult(double money) {
        return cashSuper.acceptCash(money);
    }
}
